from flask_login import login_required

from ..base import base
from ..service.CarouselService import *
from flask import request

from exts import success, page_success


@base.route('/api/carousel/add', methods=['POST'])
@login_required
def carousel_add_api():
    '''
    添加轮播信息
    :return:
    '''
    carousel = request.get_json()
    carousel_add(carousel)
    return success(carousel)


@base.route('/api/carousel/update', methods=['POST'])
@login_required
def carousel_update_api():
    '''
    更新轮播信息
    :return:
    '''
    carousel = request.get_json()
    carousel_update(carousel)
    return success(carousel)


@base.route('/api/carousel/delete', methods=['POST'])
@login_required
def carousel_delete_api():
    '''
    删除资讯信息
    :return:
    '''
    carousel = request.get_json()
    carousel_delete(carousel['id'])
    return success(carousel['id'])


@base.route('/api/carousel/detail', methods=['POST'])
@login_required
def carousel_detail_api():
    '''
    查询轮播信息
    :return:
    '''
    carousel = request.get_json()
    return success(carousel_get_by_id(carousel['id']))


@base.route('/api/carousel/page', methods=['POST'])
@login_required
def carousel_page_api():
    '''
    分页查询资讯
    :return:
    '''
    carousel = request.get_json()
    page = carousel_page(carousel['pageNum'], carousel['pageSize'])
    return page_success(page.total, page.items)


# ===================================pc web端api接口====================================================
@base.route('/api/carousel/all', methods=['GET'])
def carousel_all_api():
    '''
    查询轮播信息 web pc端
    :return:
    '''
    return success(carousel_all())
